home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-09-14 | 1.0 KB | 38 lines | [TEXT/MPS ] |
- /* This is test.g which tests a simple DLG-based scanner using string input */
-
- <<
- typedef ANTLRCommonToken ANTLRToken;
-
- #include "DLGLexer.h"
-
- main(int argc, char **argv)
- {
- if ( argc==1 ) {fprintf(stderr, "how about an argument?\n"); exit(1);}
- DLGStringInput in(argv[1]); /* create an input stream for DLG */
- DLGLexer scan(&in,2000);/* create scanner reading from stdin with bufsize==2000 */
- ANTLRTokenBuffer pipe(&scan); /* make a buffered pipe between lexer & parser */
- ANTLRToken aToken; /* create a token to fill in for DLG */
- scan.setToken(&aToken);
- Expr parser(&pipe); /* create a parser of type Expr hooked to the scanner */
- parser.init(); /* init the parser; prime lookahead etc... */
-
- parser.e(); /* start parsing at rule 'e' of that parser */
- }
- >>
-
- #token "[\ \t\n]+" <<skip();>>
- #token Eof "@"
-
- #tokclass My { IDENTIFIER NUMBER }
-
- class Expr { /* Define a grammar class */
-
- e : My My Eof
- <<fprintf(stderr, "text is %s,%s\n", $1->getText(), $2->getText());>>
- ;
-
- }
-
- #token IDENTIFIER "[a-z]+"
- #token NUMBER "[0-9]+"
-